﻿using Guru.Web.Controls.Telerik;
using System.Xml;
using System.Web;

namespace HSM.Web.UI
{
    public class HotelContextMenu : GuruContextMenu
    {
        public HotelContextMenu()
            : base()
        {
        }
        public string XMLKey
        {
            set;
            get;
        }
        public string XMLFilePath
        {
            set 
            {
                ViewState["XMLFilePath"] = value; 
            }
            get 
            {

                if (ViewState["XMLFilePath"] == null) return "~/App_Data/HotelContextMenu.xml";
                else return ViewState["XMLFilePath"].ToString();
            }
        }
        protected override void OnLoad(System.EventArgs e)
        {
            base.OnLoad(e);
            this.LoadXml(this.GetXMLConfigs());
        }
        public string GetXMLConfigs()
        {
            //load xml & cache                
            string xmlFile = HttpContext.Current.Server.MapPath(this.XMLFilePath);
            XmlDocument xmlDoc = HSMCacheManager.getHotelContextMenu(this.XMLFilePath);
            if (xmlDoc == null)
            {
                xmlDoc = new XmlDocument();
                xmlDoc.Load(xmlFile);
                HSMCacheManager.setHotelContextMenu(this.XMLFilePath, xmlDoc);
            }           

            XmlNode node = xmlDoc.SelectSingleNode(string.Format("//Session[@key=\"{0}\"]", this.XMLKey));
            return node.InnerXml;

        }
    }
}